﻿//===================================================================================
// Copyright (c) Ryan Garrett.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===================================================================================

using System;
using System.Collections.Generic;

namespace Caffeine.Core.Test.TestModel
{
    public class ModelForValidationTesting : ModelBase
    {
        private readonly ModelProperty<String> _property;
        private readonly ModelProperty<String> _property2;
        private readonly ModelProperty<String> _computedStringProperty;

        public ModelForValidationTesting()
        {
            _property = RegisterProperty<String>("Property");
            _property2 = RegisterProperty<String>("Property2");
            _computedStringProperty = RegisterComputedProperty<String, String>("ComputedStringProperty", ComputeStringValue, Property, Property2);
        }

        public ModelProperty<String> Property
        {
            get
            {
                return _property;
            }
        }

        public ModelProperty<String> Property2
        {
            get
            {
                return _property2;
            }
        }

        public ModelProperty<String> ComputedStringProperty
        {
            get
            {
                return _computedStringProperty;
            }
        }

        private static String ComputeStringValue(IEnumerable<ModelProperty<String>> properties, String newPropertyValue)
        {
            String returnValue = null;

            foreach (ModelProperty<String> property in properties)
            {
                if (!String.IsNullOrEmpty(property.Value))
                {
                    returnValue += property.Value;
                }
            }

            return returnValue;
        }
    }
}
